#ifndef SERVO_H
#define SERVO_H
#include <p18f4520.h>

//function definitions for servo.c
void write_timer0(unsigned short int);
void write_timer1(unsigned short int);
void init_usart();

/*#define set_position(x) { 
    servo_command[2] = x; \
	pos = -1; \
    PIE1 = PIE1 | 0x10; }*/

//macro defines for Timer 0 module
#define TMR0_INT_FLAG   (INTCON & 0x04)     //Timer0 interrupt flag
#define TMR1_INT_FLAG   (PIR1 & 0x01)       //Timer1 Interrupt Flag
#define CMD_SIZE        3                   //Pololu cmd size
//Value asigned to TMR0 ((65536 - 44799) * 1uS = 20ms (50Hz)
#define TMR0_VALUE ((unsigned short int) 45700)

//to go straight need TMR1 to generate interrupts every
//1.406 ms by equation ((65536 - x) * 0.5uS = 1.406ms)
//
#define SERVO_STRAIGHT ((unsigned short int) 64876)
#define SERVO_LEFT_45 ((unsigned short int) 64600)
#define SERVO_LEFT_23 ((unsigned short int) 64738)
#define SERVO_RIGHT_45 ((unsigned short int) 65091)
#define SERVO_RIGHT_23 ((unsigned short int) 64984)

/*
#define TMR0_VALUE = 45536;   //Value asigned to TMR0 ((65536 - 45536) * 0.4uS = 20ms (50Hz)
#define TRM1_VALUE = 0;       //this value should define the pulse width, from 1ms-2ms                              

#define ResetTMR0() WriteTimer0( 65536 - TMR0_VALUE )
#define ResetTMR1() WriteTimer1( 65536 - TMR1_VALUE )
*/

#endif